<!-- 页面外套 -->
<div class="page-wrapper" id="office_notice_personnelPost">

    <!-- 数据网格 -->
    <div class="datagrid datagrid-striped">
        <!-- 工具条组 -->
        <div class="tool-group">
            <form class="tool-search">
                <input type="hidden" name='page'>
                <input type="hidden" name='recPerPage'>
                <div class="im-label">
                    <div class="input-group">
                        <select class="form-control" name="sid">
                            <option value="1">搜索</option>
                        </select>
                        <span class="input-group-addon fix-border fix-padding"></span>
                        <input type="text" class="form-control" name="search">
                    </div>
                </div>
                <div class="im-label">
                    <span>申请时间</span>
                    <div class="input-group">
                        <input type="text" class="form-control" name="starttime" readonly> 
                        <span class="input-group-addon fix-border fix-padding"></span>
                        <input type="text" class="form-control" name="endtime"readonly>
                    </div>
                </div>
                <label>
                    <span>需求岗位</span>
                    <select class="form-control" name="postnumb"><!-- JS推进 --></select>
                </label>
                <label>
                    <span>审批状态</span>
                    <select class="form-control" name="state">
                        <option value="0">全部</option>
                        <option value="1">审批中</option>
                        <option value="2">审批完成</option>
                        <option value="3">打回</option>
                        <option value="4">已撤销</option>
                    </select>
                </label>
                <label><button type="button" class="btn btn-primary tool_search_btn"><i class="icon icon-search"></i> 搜索</button></label>
                <div class="clearfix"></div>
            </form>

        </div>
        <!-- tool-group -->

        <div class="datagrid-container"></div>
        <ul class="pager btn-mini" data-elements="prev,pages,next"></ul>
    </div>
    <!-- datagrid -->



    <!-- 查看盒子 -->
    <div class="modal modal-for-page fade line_show_box" aria-hidden="false">
        <div class="modal-dialog modal-fullscreen">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button>
                    <h4 class="modal-title">查看</h4>
                </div>
                <div class="modal-body modal-scroll">
                    <div class="container">
                        <table class="table detail-table">
                            <tbody><!-- JS推进 --></tbody>
                            <tfoot><tr><td colspan="3">
                                <b>抄送人</b>王
                                <div class="office-border"><div class="office-approval box_approver"><!-- JS推进 --></div></div>
                            </td></tr></tfoot>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>




</div>
<!-- page-wrapper -->

<script>
$(function() {
    //变量声明-----------------------------------------------------------------------------------------------
    var office_notice_personnelPost = $("#office_notice_personnelPost"); // 页面ID
    var office_notice_personnelPost_api = {
        datagrid : API.test_datagrid, // 数据表格
        postname : LOCAL + "Test/test_select.json", // 需求岗位
        tree: API.common_staff, // 员工树状图
        approval : LOCAL + "Test/Office/apply/attend_approval.json", // 审批人进度
        show : LOCAL + "Test/Office/apply/personnel_show.json", // 查看
        add  : API.test_response, // 添加
        edit : API.test_response, // 修改
        back : API.test_response, // 撤销
        urge : API.test_response, // 催办
    }

    //数据表格-----------------------------------------------------------------------------------------------
    //数据源
    var office_notice_personnelPost_dataSource = {
        cols   : [
            {name: "datetime",label: "申请时间",width: 140},
            {name: "username",label: "流水号",width: 100,html: true,
                valueOperator: {
                    getter: function(dataValue, cell) {
                        return `<a class="line_show_btn" dataId="${cell.config.data.id}">${dataValue}</a>`;
                    }
                }
            },
            {name: "department",label: "部门",width: 90},
            {name: "shenqingren",label: "申请人",width: 90},
            {name: "username",label: "用户名",width: 90},
            {name: "olddepartment",label: "原部门",width: 90},
            {name: "oldpost",label: "原岗位",width: 90},
            {name: "changedate",label: "调岗日期", width: 140},
            {name: "newdepartment",label: "转入部门",width: 90},
            {name: "newpost",label: "转入岗位",width: 90},
            {name: "name", label: "审批状态",width: 90},

        ],
        remote : function(){
            return zui_datagrid_remote({
                page_dom : office_notice_personnelPost, 
                url      : office_notice_personnelPost_api.datagrid
            });
        },
        remoteConverter : function(data){ 
            return zui_datagrid_filter({
                page_dom : office_notice_personnelPost,
                data     : data
            });
        }
    };
    //实例化
    office_notice_personnelPost.find('.datagrid').datagrid(
        zui_datagrid_option({
            datagrid   : office_notice_personnelPost.find('.datagrid'),
            dataSource : office_notice_personnelPost_dataSource
        })
    );
    //搜索
    office_notice_personnelPost.find('.tool_search_btn').click(function(){ 
        zui_datagrid_render({
            datagrid_obj : office_notice_personnelPost.find('.datagrid').data("zui.datagrid"),
            dataSource   : office_notice_personnelPost_dataSource
        }); 
    });

    // 操作按钮-----------------------------------------------------------------------------------------------
    // 添加
    office_notice_personnelPost.find('.tool_add_btn').click(function() {
        common_form_reset();
        common_approval_create({
            dom : office_notice_personnelPost.find('.tool_add_box .box_approver'),
            url : office_notice_personnelPost_api.approval,
            data : { 'id' : '自定义传参' }
        });
        office_notice_personnelPost.find('.tool_add_box').modal('show');
    });
    office_notice_personnelPost.find('.tool_add_submit').click(function() {
        um_data_submit({
            url: office_notice_personnelPost_api.add,
            form: office_notice_personnelPost.find('.tool_add_box form'),
            dataSource: office_notice_personnelPost_dataSource,
        });
    });

    // 修改
    office_notice_personnelPost.on('click', '.line_edit_btn', function() {
        office_notice_personnelPost.find('.line_edit_box [name="id"]').val( $(this).attr('dataId') );
        $.ajax({
            url     : office_notice_personnelPost_api.show,
            data    : { id: $(this).attr('dataId') },
            type    : "post",
            dataType: "json",
            success : function(data){
                var data = data.data;
                um_data_set(office_notice_personnelPost.find('.line_edit_box form'), data);
                office_notice_personnelPost.find('.line_edit_box').modal('show');
                // 抄送人
                common_tree_setData({
                    dom : office_notice_personnelPost.find('.line_edit_box .box_copyer'),
                    data : data.treeAll
                });
                // 审批人
                common_approval_setData({
                    dom: office_notice_personnelPost.find('.line_edit_box .box_approver'),
                    data : data.approval
                });
            }
        });
    });
    office_notice_personnelPost.find('.line_edit_submit').click(function() {
        um_data_submit({
            url: office_notice_personnelPost_api.edit,
            form: office_notice_personnelPost.find('.line_edit_box form'),
            dataSource: office_notice_personnelPost_dataSource,
        });
    });

    //查看
    office_notice_personnelPost.on("click", '.line_show_btn', function() {
        $.ajax({
            url     : office_notice_personnelPost_api.show,
            data    : { id: $(this).attr('dataId') },
            type    : "post",
            dataType: "json",
            success : function(data){
                var data = data.data;
                var temp = `
                <tr><td colspan='3'><b>流水号</b>${data.serialnumber}</td></tr>
                <tr>
                    <td><b>申请人</b>${data.shenqing}</td>
                    <td><b>用户名</b>${data.username}</td>
                </tr>
                <tr>
                    <td><b>入职日期</b>${data.ruzhi}</td>
                    <td><b>原部门</b>${data.yuanbumen}</td>
                    <td><b>原岗位</b>${data.yuangangwei}</td>
                    <td><b>转入部门</b>${data.zhuanrubumen}</td>
                    <td><b>转入岗位</b>${data.zhuanrugangwei}</td>
                    <td><b>生效日期</b>${data.shengxiao}</td>
                    <td><b>申请时间</b>${data.shenqing}</td>
                </tr>
                </tr>
                <tr><td colspan='3'><b>调岗原因</b>${data.text}</td></tr>
                `;
                office_notice_personnelPost.find('.line_show_box tbody').html(temp);
                office_notice_personnelPost.find('.line_show_box').modal('show');
                // 抄送
                common_approval_setData({
                    dom: office_notice_personnelPost.find('.line_show_box .box_approver'),
                    data : data.approval
                });
            }
        });
    });

    //撤销
    office_notice_personnelPost.on("click", '.line_back_btn', function() {
        office_notice_personnelPost.find('.line_back_box [name="id"]').val( $(this).attr('dataId') );
        office_notice_personnelPost.find('.line_back_box').modal('show');
    });
    office_notice_personnelPost.on("click", '.line_back_submit', function() {
        um_data_submit({
            url: office_notice_personnelPost_api.back,
            form: office_notice_personnelPost.find('.line_back_box form'),
            dataSource: office_notice_personnelPost_dataSource,
        });
    });

    //催办
    office_notice_personnelPost.on("click", '.line_urge_btn', function() {
        office_notice_personnelPost.find('.line_urge_box [name="id"]').val( $(this).attr('dataId') );
        office_notice_personnelPost.find('.line_urge_box').modal('show');
    });
    office_notice_personnelPost.on("click", '.line_urge_submit', function() {
        um_data_submit({
            url: office_notice_personnelPost_api.urge,
            form: office_notice_personnelPost.find('.line_urge_box form'),
            dataSource: office_notice_personnelPost_dataSource,
        });
    });

    //组件实例化---------------------------------------------------------------------------------------------
    // 日期相关
    office_notice_personnelPost.find('[name="starttime"]').datetimepicker(option_date);
    office_notice_personnelPost.find('[name="endtime"]').datetimepicker(option_date);

    // 抄送人/审批人相关
    common_tree_create({
        dom : office_notice_personnelPost.find('.tool_add_box .box_copyer'),
        url : office_notice_personnelPost_api.tree,
        is_open : true,
        is_check : true,
    });
    common_tree_create({
        dom : office_notice_personnelPost.find('.line_edit_box .box_copyer'),
        url : office_notice_personnelPost_api.tree,
        is_open : true,
        is_check : true,
    });

    // 下拉选项-需求岗位
    um_select_option({
        dom : office_notice_personnelPost.find('.tool-search [name="postnumb"]'),
        url : office_notice_personnelPost_api.postname,
        use : 'search'
    });
    um_select_option({
        dom : office_notice_personnelPost.find('.tool_add_box [name="postnumb"], .line_edit_box [name="postnumb"]'),
        url : office_notice_personnelPost_api.postname,
        use : 'select'
    });

}); // 预加载结尾
</script>
